﻿
using System;
using System.Collections.Generic;
using System.Text;

using YouHP.Utility;
using YouHP.BLL;
using YouHP.Model;
using YouHP.Model.Group;

namespace YouHP.Pages.Member.Group
{
    public class GroupIndex : YouHP.Pages.User.UserBasePage
    {
        protected GroupInfo GroupData { get; set; }
        protected List<GroupInfo> GroupListCreat { get; set; }
        protected List<GroupInfo> GroupListJoin { get; set; }
        protected int pageSize = 5;
        protected int pageIndex = 1;
        protected int groupCount;

        protected override void ShowPage()
        {
            base.ShowPage();
            if (ErrorCount > 0) return;
            this.AddLocation("用户管理中心", "/User/Index.aspx");
            this.AddLocation("圈子管理", "/User/Group/Index.aspx"); 

            HandleCommon();
            if (IsPost) HandlePost();
            else HandleGet();
        }

        protected void HandleCommon()
        {

        }

        protected void HandlePost()
        {
            int formid = RequestTools.GetFormInt("formid", 0);
            int typeid = RequestTools.GetFormInt("typeid", 0);
            int groupid = RequestTools.GetFormInt("groupid", 0);
            if (typeid == 2 && formid == 2 && groupid > 0)
            {
                int[] idArray = new int[] { groupid };
                GroupUserBLL.Instance.UpdateGroupUserRole(groupid, idArray, Constants.RoleDeleted);
            }
        }

        protected void HandleGet()
        {
            GroupListCreat = GroupBLL.Instance.GetGroupListByCreator(UserInfo.Id,pageSize,pageIndex,out groupCount);
            GroupListJoin = GroupBLL.Instance.GetGroupListByMember(UserInfo.Id);
        }
    }
}